#include "configReader.h"


int initConfig(char *filename)
{
	if (_configDictionary == NULL)
	{
		_configDictionary = iniparser_load(filename);
		if (_configDictionary == NULL)
		{
			printf("\nERROR: Could not read config file!\n");
			return -1;
		}
		return 0;
	}
	return -1;
}
int getConfigSections(arraycontainer *container)
{
	int i;
	container->numelements = iniparser_getnsec(_configDictionary);
	if (container->numelements == -1)
	{
		printf("\nERROR: No Sections found!");
		return -1;
	}
	else
	{
		container->dataarray = (char **) malloc(sizeof(char *) * container->numelements);
		for (i = 0; i < container->numelements; i++)
		{
			//container->dataarrayxx[i] = strdup(iniparser_getsecname(_configDictionary,i);
			container->dataarray[i] = iniparser_getsecname(_configDictionary,i);
		}
	}
	return 0;

}
char *getConfigValue(char *section,char *key,char *value)
{
	//Assuming all config values to	be strings.
	char completeKey[128] = {'\0'};
	sprintf(completeKey,"%s:%s",section,key);
	value = iniparser_getstring(_configDictionary,completeKey,"");
	return value;
} 
void getConfigRule(char *section,char *key,arraycontainer *rule)
{
	int i;
	char completeKey[128] = {'\0'};
	sprintf(completeKey,"%s:%s",section,key);

	//Hard-coding to 4 for now.
	rule->dataarray = (char **) malloc(sizeof(char *) * 8);
	for (i = 0; i < 8; i++)
	{
		rule->dataarray[i] = (char *) malloc(sizeof(char) * MICRO_BUFFER_SIZE);
	}
	rule->numelements = splitLine(iniparser_getstring(_configDictionary,completeKey,""),rule->dataarray,"|");
}
int deInitConfig()
{
	if (_configDictionary != NULL)
	{
		iniparser_freedict(_configDictionary);
		_configDictionary = NULL;
	}
}

void getTagMapping(char *tag,char *tableName,char *columnName)
{
	if (strcmp(tag,"") == 0)
	{
		tableName = strdup("");
		columnName = strdup("");
	}
	else if (strcmp(tag,"") == 0)
	{
	}
	else if (strcmp(tag,"") == 0)
	{
	}
	else if (strcmp(tag,"") == 0)
	{
	}
	else if (strcmp(tag,"") == 0)
	{
	}
	else if (strcmp(tag,"") == 0)
	{
	}
	else if (strcmp(tag,"") == 0)
	{
	}
}

